import Vue from 'vue'
import Router from 'vue-router'
import routes from './routers'
import { setTitle,getToken } from '@/libs/util'
import config from '@/config'
const { homeName } = config

Vue.use(Router)
const router = new Router({
    routes,
    mode: 'history'
});

// const LOGIN_PAGE_NAME = 'login'


router.beforeEach((to, from, next) => {
    if(to.meta.login&&!getToken('token')){
        next('/login')
    }else{
        next()
    }
})

router.afterEach(to => {
    setTitle(to, router.app)
    window.scrollTo(0, 0)
})

export default router
